# Kernel config based on: arch/x86/configs/lineage_T00F_defconfig

pkgname="linux-asus-t00f"
pkgver=3.10.107
pkgrel=0
pkgdesc="Asus Zenfone 5 kernel fork"
arch="x86"
_carch="x86"
_flavor="asus-t00f"
url="https://kernel.org"
license="GPL2"
options="!strip !check !tracedeps"
makedepends="perl sed installkernel bash gmp-dev bc linux-headers elfutils-dev xz"
HOSTCC="${CC:-gcc}"
HOSTCC="${HOSTCC#${CROSS_COMPILE}}"

# Source
_repository="android_kernel_asus_T00F"
_commit="ffd0a7e6f0d4ccb951f3e39aa805d9c7c6cb3291"
_config="config-${_flavor}.${arch}"
source="
	$pkgname-$_commit.tar.gz::https://github.com/zf5/${_repository}/archive/${_commit}.tar.gz
	$_config
	compiler-gcc6.h
	01_ipc-shm-fix-redefinition-of-shm_rcu_free.patch
	02_drivers-external_drivers-remove-unused-constants.patch
	03_ipc-fix-undefined-references.patch
"
builddir="$srcdir/${_repository}-${_commit}"

prepare() {
	default_prepare

	# gcc6 support
	cp -v "$srcdir/compiler-gcc6.h" "$builddir/include/linux/"

	# Remove -Werror from all makefiles
	find . -type f -name Makefile -print0 | \
		xargs -0 sed -i 's/-Werror-/-W/g'
	find . -type f -name Makefile -print0 | \
		xargs -0 sed -i 's/-Werror//g'

	# Prepare kernel config ('yes ""' for kernels lacking olddefconfig)
	cp "$srcdir"/$_config "$builddir"/.config
	yes "" | make ARCH="$_carch" HOSTCC="$HOSTCC" oldconfig
}

menuconfig() {
	cd "$builddir"
	make ARCH="$_carch" menuconfig
	cp .config "$startdir"/$_config
}

build() {
	unset LDFLAGS
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-postmarketOS"
}

package() {
	# kernel.release
	install -D "$builddir/include/config/kernel.release" \
		"$pkgdir/usr/share/kernel/$_flavor/kernel.release"

	# zImage (find the right one)
	cd "$builddir/arch/$_carch/boot"
	_target="$pkgdir/boot/vmlinuz-$_flavor"
	for _zimg in zImage-dtb Image.gz-dtb *zImage Image; do
		[ -e "$_zimg" ] || continue
		msg "zImage found: $_zimg"
		install -Dm644 "$_zimg" "$_target"
		break
	done
	if ! [ -e "$_target" ]; then
		error "Could not find zImage in $PWD!"
		return 1
	fi
}

sha512sums="98ae9cabe828b9aa3ea38c01f2294398bde4e7dbc470acb87d404d65f7526a416892c2e9a6ca9dacb69d8fe30e6b61a230beb1c4d234e16d126b3c4197564945  linux-asus-t00f-ffd0a7e6f0d4ccb951f3e39aa805d9c7c6cb3291.tar.gz
5d4c4394a6a0f889f0b327175613dfffa1aedc1af124c7e87f967766d35abed680ce581ef23b1939ae61521186b4b2c6acb6a9e1257541c448aa3bcbcb66067c  config-asus-t00f.x86
d80980e9474c82ba0ef1a6903b434d8bd1b092c40367ba543e72d2c119301c8b2d05265740e4104ca1ac5d15f6c4aa49e8776cb44264a9a28dc551e0d1850dcc  compiler-gcc6.h
0f6a9be41ed61b8407a146e8ccbc5a7abbcffe150cbba01345fcfa8e31a1554274dc2d79015f0ea68f9b394e4af5bd7040e992b3950cf03d2ce1f2454fc0d529  01_ipc-shm-fix-redefinition-of-shm_rcu_free.patch
e55a90bc89a956d83b3d978e3fae871c781544571a667468b89a9f68b626b8d39a3000ea43ae276d5e069c1ca1b2309e72a1e7b6bae53e1d78500d054de3bbd2  02_drivers-external_drivers-remove-unused-constants.patch
7dd36856b2a56216172df1a89a1c7a1cd408141605b1d0bac1a3ecd2d57d0cb1fd58ccf9dea56983597a5432947ca8bdb8789740cb968d9898ba4e36bd6d2d7e  03_ipc-fix-undefined-references.patch"
